package com.sanq.product.mcgs.common;

public class Redis {
    public static class RedisKey {
        public static final String MEMBER_TOKEN = "member:{token}:token";

        public static final String CHECK_IP_KEY = "check:incr:{ip}:{url}";

        public static final String BLOCK_IP_SET = "BLOCK_IP_SET";

        public static final String MEMBER_TREE_PERMISSION = "permission:tree:{memberId}";

        public static final String MEMBER_BUTTON_PERMISSION = "permission:button:{memberId}";
    }

    public static class ReplaceKey {
        /**
         * 得到登录用户的token
         * @param token
         * @return
         */
        public static String getMemberTokenKey(String token) {
            return RedisKey.MEMBER_TOKEN.replace("{token}", token);
        }

        /**
         * 统计该ip访问url的时长
         * @param ip
         * @param url
         * @return
         */
        public static String getCheckIpKey(String ip, String url) {
            return RedisKey.CHECK_IP_KEY.replace("{ip}", ip).replace("{url}", url);
        }

        /**
         * 获取tree的权限
         * @param id
         * @return
         */
        public static String getTreePermissionKey(Integer id) {
            String replace = "" + id;
            if (id == -1)
                replace = "*";

            return RedisKey.MEMBER_TREE_PERMISSION.replace("{memberId}", replace);
        }

        public static String getButtonPermissionKey(Integer id) {
            String replace = "" + id;
            if (id == -1)
                replace = "*";

            return RedisKey.MEMBER_BUTTON_PERMISSION.replace("{memberId}", replace);
        }

    }
}
